package com.fx.notify;/*
 * Copyright 2015 dorkbox, llc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import com.utils.TestCMD;
import dorkbox.notify.Notify;
import dorkbox.notify.Pos;
import dorkbox.util.ActionHandler;
import dorkbox.util.ImageUtil;
import dorkbox.util.LocationResolver;
import lombok.SneakyThrows;

import javax.imageio.ImageIO;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

public class NotifyTest {
//    public static final String DIALOG_CONFIRM = "dialog-confirm.png";
//    public static final String DIALOG_INFORMATION = "dialog-information.png";
//    public static final String DIALOG_WARNING = "dialog-warning.png";
//    public static final String DIALOG_ERROR = "dialog-error.png";
    /*推送通知*/

    /*推送通知*/
    public static void doNotify_normal(String str/*提示信息*/){
        Notify notify;
        //黑色进度条提示（推送）
        int count = 0;
        for (int i = 0; i < count; i++) {
            final int finalI = i;
            notify = Notify.create()
                    .title("Notify title " + i)
                    .text("This is a notification " + i + " popup message This is a notification popup message This is a " +
                            "notification popup message")
                    .hideAfter(3000)
                    .position(Pos.BOTTOM_RIGHT)
//                       .setScreen(0)
                    .darkStyle()
                    // .shake(1300, 4)
                    //.shake(1300, 10)
                    .hideCloseButton()
                    .onAction(new ActionHandler<Notify>() {
                        @Override
                        public void handle(final Notify arg0) {

                        }
                    });
            notify.show();

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }


    /*警告信息*/
    public static void doNotify(
            String title/*提示窗口标题*/,
            String str/*提示信息*/,
            String messageImage/*提示窗口图标*/
    )  {

        Notify notify;
        int count = 1;


//提示框图标显示
        InputStream resourceAsStream = LocationResolver.getResourceAsStream(/*new File("").getCanonicalPath()+File.separator+"src"+File.separator+*/"resources" + File.separator + messageImage);
        Image image = null;
        try {
            image = ImageUtil.getImageImmediate(ImageIO.read(resourceAsStream));
            // image = image.getScaledInstance(144, 104, Image.SCALE_SMOOTH);
            // image = image.getScaledInstance(104, 144, Image.SCALE_SMOOTH);
            image = image.getScaledInstance(144, 144, Image.SCALE_SMOOTH);
        } catch (IOException e) {
            e.printStackTrace();
        }


        //默认
        for (int i = 0; i < count; i++) {
            final int finalI = i;
            notify = Notify.create()
                    .title(title)
                    .text(""+str)
                    .hideAfter(2000)
                    .position(Pos.BOTTOM_RIGHT)
//                       .setScreen(0)
//                            .darkStyle()
                    // .shake(1300, 4)
                    // .shake(1300, 10)
                    // .hideCloseButton()
                    .onAction(new ActionHandler<Notify>() {
                        @Override
                        public void handle(final Notify arg0) {
                            System.err.println("Notification " + finalI + " clicked on!");
                        }
                    });

            if (i == 0) {
                notify.image(image);
                notify.show();
            } else {
                notify.showConfirm();
            }

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    /*警告信息*/
    public static void doNotifyNc(
            String title/*提示窗口标题*/,
            String str/*提示信息*/,
            String messageImage/*提示窗口图标*/
    )  {

        Notify notify = null;
        int count = 1;


//提示框图标显示
        InputStream resourceAsStream = LocationResolver.getResourceAsStream(/*new File("").getCanonicalPath()+File.separator+"src"+File.separator+*/"resources" + File.separator + messageImage);
        Image image = null;
        try {
            image = ImageUtil.getImageImmediate(ImageIO.read(resourceAsStream));
            // image = image.getScaledInstance(144, 104, Image.SCALE_SMOOTH);
            // image = image.getScaledInstance(104, 144, Image.SCALE_SMOOTH);
            image = image.getScaledInstance(144, 144, Image.SCALE_SMOOTH);
        } catch (IOException e) {
            e.printStackTrace();
        }


        //默认
        for (int i = 0; i < count; i++) {
            final int finalI = i;

            notify = Notify.create()
                    .title(title)
                    .text(""+str)
//                    .hideAfter(5000)
                    .position(Pos.BOTTOM_RIGHT)

//                       .setScreen(0)
//                            .darkStyle()
                    // .shake(1300, 4)
                    // .shake(1300, 10)
                    // .hideCloseButton()
                    .onAction(new ActionHandler<Notify>() {
                        @SneakyThrows
                        @Override
                        public void handle(final Notify arg0) {
//                            System.err.println("Notification " + finalI + " clicked on!");
                            TestCMD.cmdOpenFiles();
                        }
                    });

            if (i == 0) {
                notify.image(image);
                notify.show();
            } else {
                notify.showConfirm();
            }


        }
    }
}

